import md5 from '@/utils/blueimp-md5.js'
export default {
  data() {
    return {
      isBack: false,
      Password: '', //input输入的值
      agenPassword: '', //input输入的值

      show: false, //弹窗
      guidePages: true, //隐藏显示设置密码

      firsttime: true, //第一次设置密码
    }
  },
  onLoad() {
    // this.loadExecution() //调用设置密码页面
  },
  onBackPress() {
	  if(this.firsttime){
	    return true
	  }else{
	    this.firsttime = true
      this.isBack = false
	    return false
	  }
  },
  methods: {
    md5,
    loadExecution: function() {
      try {
        if (this.newusser) {
          this.guidePages = true
        } else {}
      } catch (e) {
        uni.setStorage({
          key: 'setpaymentPassword',
          data: true,
          success: function() {
            console.log('error时存储setpaymentPassword')
          }
        })
        this.guidePages = true
      }
      return
      uni.navigateTo({
        url: '/pages_commodity/selectRequirements/selectRequirements'
      })
    },
    //实时监控 请输入密码input输入的值

    //点击下一步密码登录
    async login() {
      //判断两次密码输入是否相同this.firsttime = false //第一次输入密码成功
      if (this.Password !== this.agenPassword) {
        uni.showToast({
          title: '两次密码不相同，请重新输入',
          duration: 1000,
          icon: 'none'
        })
        this.Password = ''
        this.agenPassword = ''
        this.firsttime = true //第一次输入密码成功
        return false
      }
      this.SetPayPassword()
    },
    async SetPayPassword() {
      try {
        let data = {
          'payPwd': this.Password
        }
        const res = await this.$api.user.SetPayPassword(data)
        console.log(res)
        if (res.code === 200) {
          this.show = true
        }
      } catch (err) {
        console.log('捕获错误', err)
      }
    },
    //第一次设置密码de下一步
    fistgoit() {
      this.firsttime = false //第一次输入密码成功
      this.isBack = true
    },
    changeInputf(e) {
      if (e.length === 6) { //验证码输入完毕，并且验证码是正确返回的
        this.Password = e
      } else {}
    },
    //第二次密码输入
    changeInputss(e) {
      if (e.length === 6) { //验证码输入完毕，并且验证码是正确返回的
        this.agenPassword = e
      } else {}
    },
    //知道了,跳转首页
    gotit() {
      uni.navigateBack({
        delta: 1
      })
      /* uni.switchTab({
        url: '/pages/index/index'
      }) */
    }
  }
}
